home *** CD-ROM | disk | FTP | other *** search
/ Belgian Amiga Club - ADF Collection / BS1 part 65.zip / BS1 part 65 / Math Visin v2.1 disk 1.adf / Arexx.WB / Simple / BioRhythm < prev    next >
Text File  |  1992-02-12  |  6KB  |  207 lines

  1. /*BioRhythm Compute your BioRhythm for this year   6-Mar-90 dh
  2.  
  3.   This simply asks for your birthday, and plots your biorhythm for this year.
  4. The year long plot is broken into 6 sections of two months each.
  5.  
  6.   However, there IS a lot of good code in this file dealing with date
  7. arithmetic, input, output, and leap years. 
  8. -------------------------------------------------------------------------- */
  9. ADDRESS "MathVision"
  10. NUMERIC DIGITS 14
  11. OPTIONS RESULTS
  12.  
  13. CycleLength.1 = 0 /* put correct rhythm information here */
  14. CycleLength.2 = 23;  CycleName.2 = "Physical     (RED)"
  15. CycleLength.3 = 28;  CycleName.3 = "Emotional    (GREEN)"
  16. CycleLength.4 = 33;  CycleName.4 = "Intellectual (BLUE)"
  17. CycleLength.5 = 0
  18.  
  19. funname.1 = "FA"
  20. funname.2 = "FB"
  21. funname.3 = "FC"
  22. funname.4 = "FD"
  23. funname.5 = "FE"
  24.  
  25. CALL InitMonth
  26.  
  27. SAY "The year-long biorhythm is plotted in 6 groups of two months each."
  28. SAY ""
  29.  
  30. Birth = GetDate("Enter your Birthday, eg. 7 Dec 41: ")
  31. PARSE VAR Birth Birthday BirthMonth BirthYear
  32.  
  33. CurrentDate = date(S)
  34. CurrentYear = Left(CurrentDate,4)
  35. CurrentMonth = SubStr(CurrentDate,5,2)
  36. CurrentDay   = Right(CurrentDate,2)
  37.  
  38. DaysOffset = DaysBetweenDates( Birthday, BirthMonth, BirthYear, 1, 1, CurrentYear )
  39. Lace "T"
  40. Hires "T"
  41. Depth 3
  42. Width 640
  43. Height 400
  44. ChangeScreen
  45. EraseScreen
  46. SimpleSampleDelta 2
  47. SimpleGradient1 "F"
  48. SimpleGradient2 "F"
  49. OverPlot "T"
  50. XMin 0
  51. XMax 62
  52. YMin .5
  53. YMax 12.5
  54. SimplePen 1
  55. Color 0 0 0 0
  56. Color 1 6 6 6
  57. Color 2 9 0 0 
  58. Color 3 0 9 0
  59. Color 4 0 0 9
  60. Color 5 12 12 12
  61.  
  62. PlotScreenToFront
  63. FA '0         " Baseline     (GRAY)'
  64. FE '(fb(a1)+fc(a1)+fd(a1))/3 " Composite (WHITE)'
  65. FF 'Sin((x+a1)*(2*pi)/a2) " generic calculation'
  66. DO i = 2 to 4
  67.   T = "FF(a1,"CycleLength.i")"
  68.   T = T '"' CycleName.i
  69.   Interpret 'Funname.i' 'T' 
  70. END
  71.  
  72. Comment1 "BioRhythm for the Year "CurrentYear", Birthdate "ConvertDate(BirthDay BirthMonth BirthYear)
  73. Comment2 "Months are grouped by twos, eg. top graph is January/February"
  74. Comment3 ""
  75.  
  76. StopSign "F"
  77.  
  78. DO Month = 1 to 12 by 2
  79.   DO i = 1 to 5
  80.     F0 Funname.i"("DaysOffset+MonthDaysAccrued.Month")/1.5+12.5-"Month
  81.     SimplePen i
  82.     PlotSimple
  83.     Get StopSign
  84.     IF (Result = "T") THEN EXIT
  85.   END    
  86. END
  87.  
  88.  
  89. exit
  90.  
  91. /*------------------------------ InitMonth -------------------------------- */
  92. InitMonth: PROCEDURE EXPOSE MonthName. MonthDays. MonthMatch. MonthDaysAccrued.
  93.   MonthName.1 = "January"     ; MonthDays.1 = 31
  94.   MonthName.2 = "February"    ; MonthDays.2 = 28
  95.   MonthName.3 = "March"       ; MonthDays.3 = 31
  96.   MonthName.4 = "April"       ; MonthDays.4 = 30
  97.   MonthName.5 = "May"         ; MonthDays.5 = 31
  98.   MonthName.6 = "June"        ; MonthDays.6 = 30
  99.   MonthName.7 = "July"        ; MonthDays.7 = 31
  100.   MonthName.8 = "August"      ; MonthDays.8 = 31
  101.   MonthName.9 = "September"   ; MonthDays.9  = 30
  102.   MonthName.10 = "October"    ; MonthDays.10 = 31
  103.   MonthName.11 = "November"   ; MonthDays.11 = 30
  104.   MonthName.12 = "December"   ; MonthDays.12 = 31
  105.  
  106.   Total = 0
  107.   DO i = 1 to 12
  108.     MonthMatch.i = UPPER(Left(MonthName.i,3))
  109.     MonthDaysAccrued.i = Total
  110.     Total = Total + MonthDays.i
  111.   END
  112. RETURN
  113.  
  114. /*---------------------------- GetDate ---------------------------- */
  115. GetDate: PROCEDURE EXPOSE MonthDays. MonthMatch. /* set Month, Day, Year */
  116.   PARSE ARG DatePrompt
  117.  
  118.   OPTIONS PROMPT DatePrompt
  119.  
  120.   IsValid = 0
  121.   DO UNTIL IsValid
  122.     PULL GDDate
  123.     GDDate = Translate( GDDate, "","/,.-():"," " )
  124.     PARSE VAR GDDate Day Month Year
  125.  
  126.     if (Year < 1000) THEN Year = Year + 1900 /* year assumed last */
  127.  
  128.     IF DATATYPE(Day,M)  /* if month in day position, swap */
  129.     THEN DO; T = Month; Month = Day; Day = T; END
  130.  
  131.     IF DATATYPE(Month,M)            /* Month alphabetic */
  132.     THEN Month = ConvertMonth( Month )
  133.     ELSE
  134.     DO
  135.       IF (Month > 12) | (Day > 31)        /* sanity check */
  136.       THEN DO; T = Month; Month = Day; Day = T; END
  137.     END
  138.   
  139.     IsValid = 0
  140.     IF ((Month>=1) & (Month<=12)) & (Day>=1)
  141.       THEN IF Day<=MonthDays.Month THEN IsValid = 1
  142.   END
  143.  
  144. RETURN Day Month Year
  145.  
  146. /*-------------------------- ConvertMonth --------------------------------- */
  147. ConvertMonth: PROCEDURE EXPOSE MonthMatch.   /* Convert "March" to "3" */ 
  148.   ARG Month
  149.   NumMonth = 0
  150.   DO i = 1 to 12
  151.     T = compare( month, MonthMatch.i, " " )
  152.     IF (T = 0 | T >=4) THEN DO; NumMonth = i; i = 1000;END
  153.   END
  154.   RETURN NumMonth
  155.  
  156. /*--------------------------- ConvertDate --------------------------------- */
  157. ConvertDate:
  158.   ARG Day Month Year
  159.   return STRIP(Day)"-"STRIP(MonthName.Month)"-"STRIP(Year)
  160.  
  161. /*--------------------------- DayInYear ----------------------------------- */
  162. DayInYear:     /* is the xth day of year */
  163.   ARG Day Month Year
  164.   If (IsLeapYear(Year) & (Month>2))
  165.     THEN RETURN MonthDaysAccrued.Month+Day+1
  166.     ELSE RETURN MonthDaysAccrued.Month+Day
  167.  
  168. /* ----------------------------- DaysInYear -------------------------------- */
  169. DaysInYear:    /* account for leap years */
  170.   ARG DYear
  171.   if IsLeapYear(DYear)
  172.     THEN RETURN(366)
  173.     ELSE RETURN(365)
  174.  
  175. /* ----------------------------- IsLeapYear ------------------------------- */
  176. IsLeapYear: /* test for leap years */
  177.   ARG IsYear
  178.   IF (IsYear//4=0)
  179.   THEN DO
  180.     IF (IsYear//100=0)
  181.       THEN DO
  182.         IF (IsYear//400=0) THEN RETURN 1 ELSE RETURN 0;
  183.       END
  184.       ELSE RETURN 1
  185.     END
  186.   ELSE RETURN 0
  187.  
  188. /*------------------------------ DaysBetweenYears --------------------------- */
  189. DaysBetweenYears: PROCEDURE   /* total of days between years */
  190.   ARG StartYear, EndYear
  191.  
  192.   Total = 0
  193.   DO Year = StartYear to EndYear-1
  194.     Total = Total + DaysInYear(Year)
  195.   END
  196.  
  197.   RETURN Total
  198.  
  199. /*---------------------------- DaysBetweenDates ----------------------------- */
  200.             /* total of days between two dates */
  201. DaysBetweenDates: PROCEDURE EXPOSE MonthDaysAccrued.
  202.   ARG sday, smonth, syear, eday, emonth, eyear
  203.   Days = DaysBetweenYears( syear, eyear )
  204.   Days = Days - DayInYear( sday smonth syear )
  205.   Days = Days + DayInYear( eday emonth eyear )
  206.   RETURN(Days)
  207.